using Domain.Dto;
using Gmmy.DomainExtension;
using Gmmy.Utility;
using System;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;

namespace Domain.Model
{
    /// <summary>
    /// 功能模块模型
    /// </summary>
    public class Module : EntityBase
    {
		#region 领域对象属性
        /// <summary>
        /// 编号
        /// </summary>
        [DisplayName(@"编号")]
        [Key]
        public Guid ID { get; set; }

        /// <summary>
        /// 父编号
        /// </summary>
        [DisplayName(@"父编号")]
        public Guid FId { get; set; }

        /// <summary>
        /// 模块名称
        /// </summary>
        [DisplayName(@"模块名称")]
        public string ModuleName { get; set; }

        /// <summary>
        /// 排序
        /// </summary>
        [DisplayName(@"排序")]
        public int Sort { get; set; }

        /// <summary>
        /// 创建时间
        /// </summary>
        [DisplayName(@"创建时间")]
        public DateTime CreateTime { get; set; }

        /// <summary>
        /// 逻辑删除
        /// </summary>
        [DisplayName(@"逻辑删除")]
        public bool IsDeleted { get; set; }


        #endregion

		#region 领域对象行为
		public Module() { }//空构造函数

		/// <summary>
        /// 创建功能模块
        /// </summary>
        /// <param name="input"></param>
        public Module(ModuleCreateInput input)
        {
            if (string.IsNullOrWhiteSpace(input.ModuleName))
            {
                throw new CustomException("请输入模块名称!");
            }
            if (input.Sort < 0)
            {
                throw new CustomException("排序不能小于0!");
            }
            ID = Guid.NewGuid();
            FId = input.FId;
            ModuleName = input.ModuleName;
            Sort = input.Sort;
            CreateTime = DateTime.Now;
            IsDeleted = false;
        }
        /// <summary>
        /// 更新功能模块
        /// </summary>
        /// <param name="input"></param>
        public void Update(ModuleUpdateInput input)
        {
            if (string.IsNullOrWhiteSpace(input.ModuleName))
            {
                throw new CustomException("请输入模块名称!");
            }
            if (input.Sort < 0)
            {
                throw new CustomException("排序不能小于0!");
            }
            FId = input.FId;
            ModuleName = input.ModuleName;
            Sort = input.Sort;
        }

        #endregion

    }
}